package exception

import (
	"xincan.com.cn/tarot-go/internal/common/constants"
	"xincan.com.cn/tarot-go/internal/common/exception"
)

// 错误码: 定义用户错误码信息
var (
	ErrUserNotFound     = constants.NewCodeStatus(5000, "用户不存在")
	ErrCreateUserFailed = constants.NewCodeStatus(5001, "创建用户失败")
	ErrSearchUserFailed = constants.NewCodeStatus(5002, "查询用户失败")
)

// UserException
// Title    		UserException
// Description   	用户异常信息结构体
// Author      		alittlexincan@163.com         						2024/07/22 11:36
// Update      		alittlexincan@163.com         						2024/07/22 11:36
type UserException struct {
	// 业务异常信息: 注入业务异常信息结构体
	*exception.BusinessException
}

// NewUserException
// Title    		NewUserException
// Description   	创建用户异常信息结构体
// Author      		alittlexincan@163.com         						2024/07/22 11:36
// Update      		alittlexincan@163.com         						2024/07/22 11:36
// Param    		err 				*exception.RuntimeException		用户异常信息结构体
// Return 			*UserException										返回用户异常信息结构体

func UserExceptionBuilder() *UserException {
	return &UserException{
		BusinessException: exception.BusinessExceptionBuilder().WithModel("验证码管理"),
	}
}

//	Error
//
// Title    		Error
// Description   	实现并重写语言内置的error
// Author      		alittlexincan@163.com         						2024/07/22 11:36
// Update      		alittlexincan@163.com         						2024/07/22 11:36
func (user *UserException) Error() string {
	return user.BusinessException.Error()
}

func (user *UserException) WithError(cs *constants.CodeStatus, err error) *UserException {
	_ = user.BusinessException.WithCode(cs.Code()).WithMessage(cs.Message()).WithError(err)
	return user
}
